package thread;

public class MultiSeller {
	public static String s="abcd";
	public static void main(String[] args) {
		
		Ticket[] pool=new Ticket[100];
		for(int i=0;i<pool.length;i++){
			Ticket t=new Ticket(i, false);
			pool[i]=t;
		}
		new Thread(new Seller(pool)).start();
		new Thread(new Seller(pool)).start();
		
	}
	
}
class Seller implements Runnable{
	private Ticket[] pool;
	
	
	public Seller(Ticket[] pool) {
		super();
		this.pool = pool;
	}


	@Override
	public void run() {
		
		for(int i=0;i<pool.length;i++){
			Ticket t=pool[i];
		
			synchronized (MultiSeller.s) {
				if(!t.isSold()){
					try {
						Thread.sleep(1);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					t.setSold(true);
					System.out.println(Thread.currentThread().getName()+" selling..."+t.getNo());
				}
			}
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}
}


class Ticket{
	private int no;
	private boolean isSold=false;
	
	public Ticket(int no, boolean isSold) {
		super();
		this.no = no;
		this.isSold = isSold;
	}
	public int getNo() {
		return no;
	}
	public void setNo(int no) {
		this.no = no;
	}
	public boolean isSold() {
		return isSold;
	}
	public void setSold(boolean isSold) {
		this.isSold = isSold;
	}
	
}
